﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cloud.Model;
using Cloud.BLL;
using Cloud.DAL;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //读取保存的Cookie信息
            HttpCookie cookies = Request.Cookies["USER_COOKIE"];
            if (cookies != null)
            {
                //如果Cookie不为空，则将Cookie里面的用户名和密码读取出来赋值给前台的文本框。
                this.username.Value = cookies["UserName"];
                this.password.Text = cookies["UserPassword"];
                //this.password.Value = cookies["UserPassword"];
                //this.password.Attributes.Add("value", cookies["UserPassword"]);
                //这里依然把记住密码的选项给选中。
                //this.ckbRememberLogin.Checked = true;
            }
        }
    }
    protected void Unnamed_Click(object sender, ImageClickEventArgs e)
    {
        USER_INFO user = USER_INFOManager.Login(this.username.Value.Trim().ToString(),this.password.Text.Trim().ToString());
        if (user != null)
        {
            Session["users"] = user;
            String i = OtherCodeService.Level(this.username.Value.Trim().ToString(), this.password.Text.Trim().ToString());
            Session["QX"] = i;
            HttpCookie cookie = new HttpCookie("USER_COOKIE");
            cookie.Values.Add("UserName", this.username.Value.Trim());
            cookie.Values.Add("UserPassword", this.password.Text.Trim());
            cookie.Expires = System.DateTime.Now.AddDays(365.0);
            HttpContext.Current.Response.Cookies.Add(cookie);
            //if (i.Equals("04"))
            //{
            //    Response.Write("<script>location.href='main1.html'</script>");
            //    return;
            //}
            //if (i.Equals("05"))
            //{
            //    Response.Write("<script>location.href='main2.html'</script>");
            //    return;
            //}
  
            if (i.Equals("07") || i.Equals("08") || i.Equals("09") || i.Equals("0A"))
            {
                Response.Write("<script>alert('功能暂未开发');</script>");
                return;
            }

            //话务中心（接电话）(u1)
            if (user.ROLE_ID.Equals("0401"))
            {
                Response.Write("<script>location.href='main0401.html'</script>");
                return;
            }
            //回访
            if (user.ROLE_ID.Equals("0454"))
            {
                Response.Write("<script>location.href='main0454.html'</script>");
                return;
            }
            //审核延期
            if (user.ROLE_ID.Equals("0452"))
            {
                Response.Write("<script>location.href='main0452.html'</script>");
                return;
            }
            //U2
            if (user.ROLE_ID.Equals("0402"))
            {
                Response.Write("<script>location.href='main0402.html'</script>");
                return;
            }
            //if (user.ROLE_ID.Equals("0500"))
            //{
            //    Response.Write("<script>location.href='main0500.html'</script>");
            //    return;
            //}
            if (user.ROLE_ID.Equals("0501"))
            {
                Response.Write("<script>location.href='main0501.html'</script>");
                return;
            }
            //if (user.ROLE_ID.Equals("0502"))
            //{
            //    Response.Write("<script>location.href='main0502.html'</script>");
            //    return;
            //}
            if (user.ROLE_ID.Equals("0601"))
            {
                Response.Write("<script>location.href='main0601.html'</script>");
                return;
            }
        }
        else
        {
            Response.Write("<script>alert('登陆失败');</script>");
            return;
        }
    }
}